import { Pipe, PipeTransform, Injectable } from '@angular/core'
import { I18NPrefixWithPipe } from './i18n-prefix-with.pipe'
import { generatePaymentBrandOptions } from 'app/utils/helpers'
import { I18NService } from '@core'

// i18n materials of payment brand is prefix with PAYMENT_BRAND.
@Pipe({ name: 'i18nChanCode' })
@Injectable({
  providedIn: 'root',
})
export class I18NChanCodePipe implements PipeTransform {
  constructor(private i18nPrefixWithPipe: I18NPrefixWithPipe, private i18n: I18NService) {}

  transform(value: string): string {
    if (value === '') return this.i18n.fanyi('GENERAL.INFO.UNKOWN')
    const options: string[] = generatePaymentBrandOptions().map(item => item.value)
    if (options.includes(value)) {
      return this.i18nPrefixWithPipe.transform(value, 'PAYMENT_BRAND.')
    } else {
      return this.i18n.fanyi('GENERAL.INFO.UNKOWN')
    }
  }
}
